<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let point1 = [0,0,0]
        let point2 = [0,1,0]
        let point3 = [0,1,1]


        /*  怎么用mediapipe和纯前端实现深蹲计数和俯卧撑计数
            1.3维点(输入：getusermedia .输出：mediapipe)
            2.计算夹角(空间向量)
        */
        function countAngle(point1,point2,point3){
            // 1.先求 point1 和point2之间的距离
            let temp12  =  Math.pow((point1[0]-point2[0]),2)+  Math.pow((point1[1]-point2[1]),2) +Math.pow((point1[2]-point2[2]),2)
            let point12 = Math.pow(temp12,0.5)
            // console.log(point12)
            let temp23  =  Math.pow((point3[0]-point2[0]),2)+  Math.pow((point3[1]-point2[1]),2) +Math.pow((point3[2]-point2[2]),2)
            let point23 = Math.pow(temp23,0.5)
            // console.log(point23)

            // 2.求向量 
            let vector12 = [(point1[0]-point2[0]),(point1[1]-point2[1]),(point1[2]-point2[2])]
            let vector23 = [(point3[0]-point2[0]),(point3[1]-point2[1]),(point3[2]-point2[2])]
            
            
            //3.求arccos 
            let top = vector12[0] * vector23[0] + vector12[1] * vector23[1] + vector12[2] * vector23[2]
            let bottom = point12 * point23

            // 4.最后求解
            console.log(Math.acos(top / bottom)* 180 / Math.PI)
        }
        countAngle(point1,point2,point3)
    </script>
</body>
</html>